package com.gko100.dao.impl;

import java.util.List;


import com.gko100.dao.MessageDao;
import com.gko100.dao.basehibernatesupport.BaseHibernateDaoSupport;
import com.gko100.model.Message;

public class MessageDaoHibernate extends BaseHibernateDaoSupport implements MessageDao {

	public void delete(Message message) {
		
		this.getHibernateTemplate().delete(message);
		
	}

	public List<Message> findMessageAll() {
		
		List<Message> mList = this.getHibernateTemplate().find("from Message as m order by m.replyFlag, m.addDate");
		if(mList!=null&&mList.size()>=1){
			
			return mList;
		}else{
			
			System.out.println(this.getClass().getName()+"---"+new Exception().getStackTrace()[0].getMethodName()+"---mList======null");
			return null;
		}
	}

	public Message findMessageByMId(Integer mId) {
		
		Message message = this.getHibernateTemplate().get(Message.class, mId);
		if(message!=null){
			return message;
		}else{
			
			System.out.println(this.getClass().getName()+"---"+new Exception().getStackTrace()[0].getMethodName()+"---message======null");
			return null;
		}
		
	}

	public void save(Message message) {
		
		this.getHibernateTemplate().save(message);
		
	}

	public void update(Message message) {
		
		this.getHibernateTemplate().update(message);
		
	}

	
}
